package main.com.oaer.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import main.com.oaer.dao.RoleDao;
import main.com.oaer.dao.RolePurviewDao;
import main.com.oaer.dao.UserRoleDao;
import main.com.oaer.model.Role;
import main.com.oaer.service.RoleService;

@Service
public class RoleServiceImpl implements  RoleService {

	@Autowired
	RoleDao roleDao;
	
	@Autowired
	RolePurviewDao rolePurviewDao;
	
	@Autowired
	UserRoleDao userRoleDao;
	
	@Override
	public void add(Role role) {
		roleDao.add(role);
	}

	@Override
	public List<Role> findRoles() {
		return roleDao.findRoles();
	}

	@Override
	public void delete(Role role) {
		roleDao.delete(role);
		rolePurviewDao.deleteByRoleId(role.getRoleId());
		userRoleDao.deleteByRoleId(role.getRoleId());
	}

	@Override
	public Role load(Long id) {
		return roleDao.load(id);
	}

}
